﻿<UserControl x:Class="FIFP.DashBoard.Views.OverlapManagement"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"    
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:Presentation="clr-namespace:FIFP.Common.Behaviors.CommonEventArgs;assembly=FIFP.Common"
    xmlns:local="clr-namespace:FIFP.DashBoard.Views"
    xmlns:converter="clr-namespace:FIFP.DashBoard.Converters"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    DataContext="{Binding OverlapVM,Source={StaticResource ServiceLocator}}"         
    mc:Ignorable="d"             
    d:DesignHeight="600" d:DesignWidth="800">

    <UserControl.Resources>
        <converter:TrueToFalseConverter x:Key="TrueFalseConverter" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="{StaticResource MainBackground}" Margin="0,5,0,0">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="180"/>
            <ColumnDefinition Width="*"/>           
        </Grid.ColumnDefinitions>

        <StackPanel Name="SingleUnitTypePanel">
            <Border BorderThickness="0" Margin="1,1,1,0" Background="{StaticResource FilterBackground}">
                <TextBlock TextWrapping="Wrap" Text="Single Unit" Style="{StaticResource SmallHeading}" VerticalAlignment="Center" Margin="5,0"/>
            </Border>
            <ListBox Margin="2,5,0,0"  ItemsSource="{Binding UnitTypeList}" Background="#FF303440" Foreground="Gray" BorderBrush="{x:Null}"  >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <RadioButton Name="radioUnitType" ClickMode="Press" Tag="{Binding }" Content="{Binding }"
                                     Command="{Binding Source={StaticResource ServiceLocator},Path=OverlapVM.CheckedUnitTypeEvent}" CommandParameter="{Binding ElementName=radioUnitType}"
                                     Foreground="Gray" FontSize="11"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <Button Content="Overlap Check" Name="btnOverlapCheckingOnEachUnit" Width="140" Margin="0,15,20,0" Style="{StaticResource ButtonStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding OverLapCheckingCommand}" 
        							           CommandParameter="{Binding ElementName=btnOverlapCheckingOnEachUnit}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>

            <Border BorderThickness="0" Margin="1,15,1,0" Background="{StaticResource FilterBackground}">
                <TextBlock TextWrapping="Wrap" Text="Tower And Wells" Style="{StaticResource SmallHeading}" VerticalAlignment="Center" Margin="5,0"/>
            </Border>

            <Button Content="Overlap Check" Name="btnOverlapCheckingOnTowerWell" Width="140" Margin="0,15,20,0" Style="{StaticResource ButtonStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding OverLapCheckingCommand}" 
        							           CommandParameter="{Binding ElementName=btnOverlapCheckingOnTowerWell}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>

            <Border BorderThickness="0" Margin="1,15,1,0" Background="{StaticResource FilterBackground}">
                <TextBlock TextWrapping="Wrap" Text="Tower And Pipelines" Style="{StaticResource SmallHeading}" VerticalAlignment="Center" Margin="5,0"/>
            </Border>

            <Button Content="Overlap Check" Name="btnOverlapCheckingOnTowerPipeline" Width="140" Margin="0,15,20,0" Style="{StaticResource ButtonStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding OverLapCheckingCommand}" 
        							           CommandParameter="{Binding ElementName=btnOverlapCheckingOnTowerPipeline}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            
            <Border BorderThickness="0" Margin="1,15,1,0" Background="{StaticResource FilterBackground}">
                <TextBlock TextWrapping="Wrap" Text="Well And Pipelines" Style="{StaticResource SmallHeading}" VerticalAlignment="Center" Margin="5,0"/>
            </Border>

            <Button Content="Overlap Check" Name="btnOverlapCheckingOnWellPipeline" Width="140" Margin="0,15,20,0" Style="{StaticResource ButtonStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding OverLapCheckingCommand}" 
        							           CommandParameter="{Binding ElementName=btnOverlapCheckingOnWellPipeline}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
                                  
            <Border BorderThickness="0" Margin="1,30,1,0" Background="{StaticResource FilterBackground}">
                <TextBlock TextWrapping="Wrap" Text="Alfa Tower" Style="{StaticResource SmallHeading}" VerticalAlignment="Center" Margin="5,0"/>                
            </Border>

            <Button Content="Overlap Check" Name="btnOverlapCheckingOnAlfaTower" Width="140" Margin="0,15,20,0" Style="{StaticResource ButtonStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding OverLapCheckingCommand}" 
        							           CommandParameter="{Binding ElementName=btnOverlapCheckingOnAlfaTower}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>            

        </StackPanel>

        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
                  
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <StackPanel x:Name="overlapPanel"  Orientation="Vertical" Grid.Column="0" Margin="0,0,20,0" >
                    <TextBlock Text="Overlapped Locations" Style="{StaticResource SmallHeading}" VerticalAlignment="Top" Margin="0,0,0,8"/>
                                                          
                    <sdk:DataGrid x:Name="overlapGroupGrid" ItemsSource="{Binding OverlapGroups}" AutoGenerateColumns="False" 
                             Style="{StaticResource DataGridStyle}" RowHeaderStyle="{StaticResource DataGridRowHeaderStyle1}" 
                                  ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" RowStyle="{StaticResource DataGridRowStyle}" 
                                  CellStyle="{StaticResource DataGridCellStyle}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Loaded">
                                <i:InvokeCommandAction Command="{Binding OverlapGroupLoadCommand}" 
        							CommandParameter="{Binding ElementName=overlapGroupGrid}" />
                            </i:EventTrigger>

                            <i:EventTrigger EventName="SelectionChanged">
                                <Presentation:InvokeDelegateCommandAction
                                Command="{Binding Source={StaticResource ServiceLocator},Path=OverlapVM.OverlapGroupSelectChange}"
                                CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=InvokeParameter}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    <sdk:DataGrid.Columns>
                            <sdk:DataGridTextColumn Header="Unit Name" Binding="{Binding OverlapLocation}" Width="140"  />
                    </sdk:DataGrid.Columns>
                    </sdk:DataGrid>
                </StackPanel>

                <StackPanel x:Name="overlapPlansPanel" Orientation="Vertical" Grid.Column="1" Margin="0,0,15,0">

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Overlapped Plans" Style="{StaticResource SmallHeading}" VerticalAlignment="Top" Margin="0,0,0,8"/>

                        <Button Tag="simops" Name="btnApplySimops" Content="Apply SIMOPS"  Style="{StaticResource ButtonStyle}"  
                                IsEnabled="{Binding IsApplySimopsButtonEnabled}" Margin="30,2,0,5">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <i:InvokeCommandAction Command="{Binding ApplySimopsCommand}" 
        							                    CommandParameter="{Binding ElementName=btnApplySimops}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>

                        <Button Name="btnSelectedCheckOverlapGroup" Content="Check Overlap"  Style="{StaticResource ButtonStyle}" 
                                IsEnabled="{Binding IsCheckOverlapButtonEnabled}" Margin="170,2,0,5">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <i:InvokeCommandAction Command="{Binding CheckSelectedOverlapGroupCommand}" 
        							                   CommandParameter="{Binding ElementName=btnSelectedCheckOverlapGroup}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>                      
                    </StackPanel>
                    
                    <sdk:DataGrid x:Name="overlapPlansGrid" ItemsSource="{Binding SelectedAppointments}" AutoGenerateColumns="False" 
                           Style="{StaticResource DataGridStyle}" RowHeaderStyle="{StaticResource DataGridRowHeaderStyle1}" 
                                  ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" RowStyle="{StaticResource DataGridRowStyle}" 
                                  CellStyle="{StaticResource DataGridCellStyle}">

                    <sdk:DataGrid.Columns>
                    <sdk:DataGridTemplateColumn Header="">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                        <CheckBox Name="chkPlans" Tag="{Binding}" IsEnabled="{Binding IsAppliedSimops,Converter={StaticResource TrueFalseConverter}}"
                                                  IsChecked="{Binding IsAppliedSimops, Mode=TwoWay}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Checked">
                                                    <i:InvokeCommandAction Command="{Binding Source={StaticResource ServiceLocator}, Path=OverlapVM.OverlapActivityCheckedCommand}" CommandParameter="{Binding ElementName=chkPlans}" />
                                                </i:EventTrigger>
                                                <i:EventTrigger EventName="Unchecked">
                                                    <i:InvokeCommandAction Command="{Binding Source={StaticResource ServiceLocator}, Path=OverlapVM.OverlapActivityUnCheckedCommand}" CommandParameter="{Binding ElementName=chkPlans}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </CheckBox>
                                    </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>

                    <sdk:DataGridTextColumn Header="Activity"   Binding="{Binding ActivityType, Mode=TwoWay}"  Width="90"/>
                    <sdk:DataGridTextColumn Header="Unit Name"  Binding="{Binding UnitName, Mode=OneWay}"  Width="90"/>
                    <sdk:DataGridTextColumn Header="Division"   Binding="{Binding Division, Mode=OneWay}"  Width="90"/>
                    <sdk:DataGridTextColumn Header="Start Date" Binding="{Binding OriginalStart, Mode=OneWay, StringFormat=yyyy-MM-dd}"  Width="100"/>
                    <sdk:DataGridTextColumn Header="End Date"   Binding="{Binding OriginalEnd,   Mode=OneWay, StringFormat=yyyy-MM-dd}"  Width="90"/>
                </sdk:DataGrid.Columns>

            </sdk:DataGrid>
            
           
                </StackPanel>

                <StackPanel x:Name="planReschedulePanel" Orientation="Vertical" Grid.Column="2">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Plan Rescheduled" Style="{StaticResource SmallHeading}" VerticalAlignment="Top" Margin="0,0,0,8"/>
                        <Button Content="Cancel SIMOPS" Name="btnCancelSimops" Style="{StaticResource ButtonStyle}" 
                                IsEnabled="{Binding IsCancelSimopsButtonEnabled}" Margin="30,2,0,5">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <i:InvokeCommandAction Command="{Binding CancelSimopsCommand}" 
        							                    CommandParameter="{Binding ElementName=btnCancelSimops}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>

                        </Button>
                    </StackPanel>
                   
                    <sdk:DataGrid x:Name="planRescheduledGrid" ItemsSource="{Binding SelectedAppointments}" AutoGenerateColumns="False" 
                           Style="{StaticResource DataGridStyle}" RowHeaderStyle="{StaticResource DataGridRowHeaderStyle1}" 
                                  ColumnHeaderStyle="{StaticResource DataGridColumnHeaderStyle}" RowStyle="{StaticResource DataGridRowStyle}" 
                                  CellStyle="{StaticResource DataGridCellStyle}" IsReadOnly="False">                        
                                                
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTemplateColumn Header="">
                                <sdk:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <CheckBox Name="chkCancelPlans" Tag="{Binding}" IsEnabled="{Binding IsAppliedSimops}"
                                                   IsChecked="{Binding IsSelectedForCancelSimops, Mode=TwoWay}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Checked">
                                                    <i:InvokeCommandAction Command="{Binding Source={StaticResource ServiceLocator}, Path=OverlapVM.SimopsActivityCheckedCommand}" CommandParameter="{Binding ElementName=chkCancelPlans}" />
                                                </i:EventTrigger>
                                                <i:EventTrigger EventName="Unchecked">
                                                    <i:InvokeCommandAction Command="{Binding Source={StaticResource ServiceLocator}, Path=OverlapVM.SimopsActivityUnCheckedCommand}" CommandParameter="{Binding ElementName=chkCancelPlans}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </CheckBox>
                                    </DataTemplate>
                                </sdk:DataGridTemplateColumn.CellTemplate>
                            </sdk:DataGridTemplateColumn>


                            <sdk:DataGridTextColumn Header="Start Date" Binding="{Binding Start, Mode=OneWay, StringFormat=yyyy-MM-dd}" Width="100"/>
                            <sdk:DataGridTextColumn Header="End Date"   Binding="{Binding End, Mode=OneWay, StringFormat=yyyy-MM-dd}" Width="90" />
                            <sdk:DataGridTextColumn Header="Reason"  Binding="{Binding ModificationReason, Mode=TwoWay}"/>
                </sdk:DataGrid.Columns>

            </sdk:DataGrid>

                </StackPanel>               
            </Grid>
            
            <Path Data="M25.666672,37 L204.34454,37" Margin="0,20,0,0" Grid.Row="1" Stretch="Fill" StrokeThickness="1" UseLayoutRounding="False" VerticalAlignment="Top" Height="1" Stroke="{StaticResource LineColor}"/>

            <Grid Margin="0,10,0,0" Grid.Row="2" >
                <local:UCAppointment_New x:Name="overlapAppointment" />
            </Grid>

        </Grid>    
                  
    </Grid>
</UserControl>
